#-*- coding:utf-8 -*- 
'''
Created on 2011-11-2

@author: Botao Wu
'''

import string

'''string.maketrans(intab, outtab) --> This method returns a translation table 
that maps each character in the intab string into the character at the same position 
in the outtab string. Then this table is passed to the translate() function. 
Note that both intab and outtab must have the same length.'''

s = 'abcdefg-1234567'
table = string.maketrans('', '') #没有映射，实际上就是按原始字符保留，看下面用到translate中时的效果
print s.translate(table)  # 输出abcdefg-1234567
print s.translate(table, 'abc123') #输出defg-4567 可以看到删除了字符abc123

#下面再看有字符映射时的效果
table = string.maketrans('abc', 'ABC') #用于translate中时的效果如下
#输出ABCdefg-1234567 就是将abc映射为大写的ABC，前提是abc如果被保留下来了
print s.translate(table) 
#输出Cdefg-4567 先把s中的ab123去除了，然后在保留下来的字符中应用table中指定的字符映射关系映射：c -> C
print s.translate(table, 'ab123')  

